/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.element.steuer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.ProgressBar;

import de.mnit.basis.fehler.Fehler;

/**
 * @author Michael Nitsche
 */
public class SWT_Fortschritt extends A_SWT_Steuer<SWT_Fortschritt,ProgressBar> {

	private final boolean vert_n_horiz;


	public SWT_Fortschritt(boolean vert_n_horiz) {
		this.vert_n_horiz=vert_n_horiz;
	}


	// SETZEN

	public SWT_Fortschritt sMinMax(int min, int max) {
		Fehler.zahl.wenn_ZuKlein(0,min);
		Fehler.zahl.wenn_ZuGross(max-1,min);
		for(int i=1; i<=2; i++) {
			swt().setMinimum(min);
			swt().setMaximum(max);
			swt().setSelection(min);
		}
		return this;
	}

	public SWT_Fortschritt sWert(int wert) {
		Fehler.zahl.wenn_Ausserhalb(swt().getMinimum(),swt().getMaximum(),wert);
		swt().setSelection(wert);
		return this;
	}

	public SWT_Fortschritt weiter() {
		int wert=gWert();
		wert++;
		if(wert<=gMax()) this.sWert(wert);
		return this;
	}

	// LESEN

	public Integer gMax()    	{ return swt().getMaximum(); }
	public Integer gMin()		{ return swt().getMinimum(); }
	public Integer gWert()   	{ return swt().getSelection(); }
	public boolean gWeiter()   	{ return this.gWert()<this.gMax(); }

	// ERZEUGEN

	protected int style3() {
		return this.vert_n_horiz ? SWT.VERTICAL : SWT.HORIZONTAL;
	}

	protected ProgressBar roh(Composite basis, int style) {
		return new ProgressBar(basis,style);
	}

	protected void init3() {}

}
